<?php

namespace app\interfaces\model;

use think\Model;

class SignLog extends Model
{
    protected $autoWriteTimestamp = 'datetime';
    protected $createTime = false;

    public function getUnionAttr($value, $data)
    {
        return $this->getphone($data['unionid'], 4, 6);
    }

    function getphone($phone, $start = 3, $len = 4)
    {
        // $start = $start > 11 ? 11 : $start;
        // if (($start + $len) > 11) {
        //     $len = 11 - $start;
        // }
        $star = '';

        for ($i = 0; $i < $len; $i++) {
            $star .= '*';
        }

        $head = substr($phone, 0, $start);

        $end = substr($phone, $start + $len);

        return $head . $star . $end;
    }
}